package com.kgc.cgconsumer.Aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Aspect
@Component
public class LoggerAspect {
    Logger logger = LoggerFactory.getLogger(LoggerAspect.class);

    @Pointcut("execution(* com.kgc.cgconsumer.Controller..*.*(..))")
    public void point() {

    }
    @Before("point()")
    public void before(JoinPoint jp) {
        logger.info("AOP before - class :" + jp.getTarget() + "method : " + jp.getSignature().getName() + " params :"
                + Arrays.toString(jp.getArgs()));
    }
    @AfterReturning(pointcut = "point()", returning = "result")
    public void afterReturning(JoinPoint jp, Object result) {
        logger.info("AOP afterReturning - class: " + jp.getTarget().getClass().getName() +
                ", method: " + jp.getSignature().getName() +
                ", params: " + Arrays.toString(jp.getArgs()) +
                ", result: " + result);
    }

}
